package com.jingyi.web.controller.wechat;

import com.jingyi.common.annotation.Log;
import com.jingyi.common.core.controller.BaseController;
import com.jingyi.common.core.domain.AjaxResult;
import com.jingyi.common.core.domain.entity.WxUser;
import com.jingyi.common.core.domain.entity.WxUserMedicalRecord;
import com.jingyi.common.core.page.TableDataInfo;
import com.jingyi.common.enums.BusinessType;
import com.jingyi.system.service.IWxUserMedicalRecordService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * 微信患者医疗记录
 *
 * @author jingyi
 */
@RestController
@RequestMapping("/wxchat/record")
public class WxUserMedicalController extends BaseController {

    @Autowired
    private IWxUserMedicalRecordService wxUserMedicalRecordService;

    /**
     * 根据条件分页查询微信患者医疗记录
     *
     * @param record 微信患者医疗记录
     * @return 微信患者医疗记录集合信息
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @GetMapping("/list")
    public TableDataInfo list(WxUserMedicalRecord record)
    {
        startPage();
        List<WxUserMedicalRecord> list = wxUserMedicalRecordService.selectRecordList(record);
        return getDataTable(list);
    }

    /**
     * 根据条件查询微信患者医疗记录
     *
     * @param record 微信患者医疗记录
     * @return 微信患者医疗记录集合信息
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @PostMapping("/listAll")
    public AjaxResult listAll(@RequestBody WxUserMedicalRecord record)
    {
        List<WxUserMedicalRecord> list = wxUserMedicalRecordService.selectRecordList(record);
        return success(list);
    }

    /**
     * 通过记录ID查询微信患者医疗记录
     *
     * @param recordId 微信患者医疗记录ID
     * @return 微信患者医疗记录对象信息
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable Long recordId)
    {
        return success(wxUserMedicalRecordService.selectRecordById(recordId));
    }

    /**
     * 通过微信患者ID和状态查询微信患者医疗记录
     * @param userId 微信患者ID
     * @param state 状态
     * @return
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @GetMapping(value = "/getRecordByUserIdAndState")
    public AjaxResult  getRecordByUserIdAndState(Long userId,String state){
        return success(wxUserMedicalRecordService.selectRecordByUserIdAndState(userId,state));
    }

    /**
     * 通过微信患者ID查询微信患者医疗记录
     *
     * @param userId 微信患者ID
     * @return
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @GetMapping(value = "/getRecordByUserId/{userId}")
    public AjaxResult getRecordByUserId(@PathVariable Long userId){
        return success(wxUserMedicalRecordService.selectRecordByUserId(userId));
    }

    /**
     * 审核微信患者医疗记录
     * @param record 微信患者医疗记录对象信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('wx:user:edit')")
    @GetMapping(value = "/auditRecordInfo")
    public AjaxResult  auditRecordInfo(WxUserMedicalRecord record){
        record.setAuditBy(getUsername());
        return success(wxUserMedicalRecordService.auditRecordInfo(record));
    }

    /**
     * 处理微信患者医疗记录
     * @param record 微信患者医疗记录对象信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('wx:user:edit')")
    @GetMapping(value = "/processRecordInfo")
    public AjaxResult  processRecordInfo(WxUserMedicalRecord record){
        record.setProcessBy(getUsername());
        return success(wxUserMedicalRecordService.processRecordInfo(record));
    }

    /**
     * 新增微信患者医疗记录信息
     *
     * @param record 微信患者医疗记录信息
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @Log(title = "患者医疗记录信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody WxUserMedicalRecord record)
    {
        record.setCreateBy(getUsername());
        return toAjax(wxUserMedicalRecordService.insertRecord(record));
    }

    /**
     * 修改微信患者医疗记录信息
     *
     * @param record 微信患者医疗记录信息
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @Log(title = "患者医疗记录信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody WxUserMedicalRecord record)
    {
        record.setUpdateBy(getUsername());
        return toAjax(wxUserMedicalRecordService.updateRecord(record));
    }

    /**
     * 批量删除微信患者医疗记录信息
     *
     * @param recordIds 需要删除的微信患者医疗记录ID
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('wx:user:query')")
    @Log(title = "患者医疗记录信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(wxUserMedicalRecordService.deleteRecordByIds(recordIds));
    }


}
